package com.jwds.digital.bios.business.service.config;

import io.netty.util.concurrent.DefaultThreadFactory;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * <p>ThreadPoolConfig</p>
 *
 * @author 林柏云
 * @Date：2024/11/20 10:35
 */
@Configuration
public class ThreadPoolConfig {
  @Bean(name = "oneMinBeltTaskThreadPool")
  public ThreadPoolTaskExecutor threadPoolTaskExecutor1() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5); // 核心线程数
    executor.setMaxPoolSize(10); // 最大线程数
    executor.setQueueCapacity(100); // 队列容量
    executor.setKeepAliveSeconds(30); // 线程存活时间
    executor.setThreadNamePrefix("on-min-belt-thread-"); // 线程名前缀
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
    return executor;
  }

  @Bean(name = "routeJobTaskThreadPool")
  public ThreadPoolTaskExecutor threadPoolTaskExecutor2() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5); // 核心线程数
    executor.setMaxPoolSize(10); // 最大线程数
    executor.setQueueCapacity(100); // 队列容量
    executor.setKeepAliveSeconds(30); // 线程存活时间
    executor.setThreadNamePrefix("route-job-thread-"); // 线程名前缀
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
    return executor;
  }

//  @Bean(name = "scheduledThreadPoolExecutor")
//  public ScheduledThreadPoolExecutor scheduledThreadPoolExecutor() {
//    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5, new DefaultThreadFactory("scheduled-job-thread-"), new ThreadPoolExecutor.CallerRunsPolicy());
//    return executor;
//  }
}
